home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XA_6S.ZIP / SOURCE / EVNT_MUL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-07  |  3.3 KB  |  135 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <memory.h>
  9. #include "EVENT_Q.H"
  10. #include "XA_DEFS.H"
  11. #include "XA_GLOBL.H"
  12. #include "XA_TYPES.H"
  13. #include "K_DEFS.H"
  14. #include "RECTLIST.H"
  15. #include "OBJECTS.H"
  16.  
  17. /*
  18.     The essential evnt_multi() call
  19. */
  20. unsigned long XA_evnt_multi(short clnt_pid,AESPB *pb)
  21. {
  22.     short events=pb->intin[0];
  23.     unsigned long ret=XAC_DONE;
  24.     short f,rtn,new_waiting_for=0;
  25.     short *clnt_buf=(short*)(pb->addrin[0]);
  26.     XA_AESMSG_LIST *msg;
  27.     WidgetCallback wc,disp;
  28.     XA_PENDING_WIDGET *pending;
  29.     XA_WIDGET *widg;
  30.     XA_WINDOW *wind;
  31.  
  32.     clients[clnt_pid].waiting_pb=pb;    /* Store a pointer to the AESPB to fill when the event(s) */
  33.                                         /*  finally arrive. */
  34.     
  35.     if (events&MU_BUTTON)
  36.     {
  37.         new_waiting_for|=XAWAIT_BUTTON;    /* Flag the app as waiting for messages */
  38.         ret=XAC_BLOCK;
  39.     }
  40.     
  41.     if (events&MU_KEYBD)
  42.     {
  43.         new_waiting_for|=XAWAIT_KEY;    /* Flag the app as waiting for messages */
  44.         ret=XAC_BLOCK;
  45.     }
  46.         
  47.     if (events&MU_MESAG)
  48.     {
  49. /* Is there a widget still active (like a scroll arrow)? If so, check with the action first */
  50. /* as it may result in some messages (just in case we've not got any already) */
  51.         if (!clients[clnt_pid].msg)
  52.         {
  53.             if (clients[clnt_pid].widget_active)
  54.             {
  55.                 pending=clients[clnt_pid].widget_active;
  56.                 wc=pending->action;
  57.                 widg=pending->widg;
  58.                 wind=pending->wind;
  59.                 rtn=(*wc)(pending->wind, pending->widg);    /* Call the pending action */
  60.  
  61.                 if (rtn)    /* If the widget click/drag function returned TRUE we reset the state of the widget */
  62.                 {
  63.                     XA_RECT_LIST *rl=rect_get_system_first(wind);
  64.  
  65.                     widg->stat=XAW_PLAIN;                    /* Flag the widget as de-selected */
  66.                     disp=widg->behaviour[XACB_DISPLAY];        /* get the redraw function for this widget */
  67.  
  68.                     v_hide_c(V_handle);
  69.                     for(rl=rl; rl; rl=rect_get_system_next(wind))    /* Walk the rectangle list */
  70.                     {
  71.                         set_clip(rl->x, rl->y, rl->w, rl->h);
  72.                         (*disp)(wind, widg);
  73.                     }
  74.                     v_show_c(V_handle, 1);
  75.                 }
  76.             }
  77.         }
  78.  
  79.         if (clients[clnt_pid].msg)    /* Are there any messages pending? */
  80.         {
  81.             msg=clients[clnt_pid].msg;
  82.             clients[clnt_pid].msg=msg->next;
  83.         
  84.             for(f=0; f<8; f++)        /* Copy the message into the clients buffer */
  85.                 clnt_buf[f]=msg->message[f];
  86.  
  87.             pb->intout[0]=MU_MESAG;
  88.             
  89.             return XAC_DONE;        /* Return XAC_DONE to unblock the client */
  90.         }
  91.     
  92.         new_waiting_for|=XAWAIT_MESSAGE;            /* Mark the client as waiting for messages */
  93.     
  94.         if (ret==XAC_DONE)
  95.             ret=XAC_BLOCK;
  96.     }
  97.     
  98.     if (events&MU_TIMER)
  99.     {
  100.         if (pb->intin[15])
  101.         {
  102.             ret=0xffff0000L|XAC_M_TIMEOUT;
  103.         }else{
  104.             if (pb->intin[14])
  105.                 ret=(pb->intin[14]<<16)|XAC_M_TIMEOUT;
  106.         }
  107.         
  108.         if (ret&XAC_M_TIMEOUT)
  109.         {
  110.             new_waiting_for|=XAWAIT_TIMER;    /* Flag the app as waiting for a timer */
  111.         }else{
  112.             pb->intout[0]=MU_TIMER;
  113.             new_waiting_for=0;
  114.             ret=XAC_DONE;
  115.         }
  116.         
  117.     }
  118.  
  119.     if (new_waiting_for)        /* If we actually recognised any of the codes, then set the multi flag */
  120.         new_waiting_for|=XAWAIT_MULTI;
  121.     
  122.     clients[clnt_pid].waiting_for=new_waiting_for;    /* Flag the app as waiting for messages */
  123.  
  124.     return ret;
  125. }
  126.  
  127. /*
  128.     Cancel an event_multi()
  129.     - called when any one of the events we were waiting for occurs
  130. */
  131. void cancel_evnt_multi(short clnt_pid)
  132. {
  133.     clients[clnt_pid].waiting_for=0;
  134. }
  135.